package com.t.bricks.bussiness.db.dao.modulemanage.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.t.bricks.bussiness.db.dao.modulemanage.ModuleManageDao;
import com.t.bricks.bussiness.db.entity.modulemanage.ModuleManage;
import com.t.bricks.bussiness.db.mapper.modulemanage.ModuleManageMapper;
import com.t.bricks.model.Log;
import com.t.bricks.model.MsgEmity;

@Repository
public class ModuleManageDaoImpl implements ModuleManageDao<ModuleManage> {
	
	@Autowired
	private ModuleManageMapper moduleManageMapper;

	/**
	 * 保存模块对应的图标
	 * @param sId 选取的记录编号
	 * @param sIconStyle 图标的样式
	 * @return
	 */
	@Override
	public MsgEmity saveIcon(String sId, String sIconStyle) {
		try {
			int i = moduleManageMapper.setIcon(sId, sIconStyle);
			if (i < 1) {
				ModuleManage moduleManage = new ModuleManage();
				moduleManage.setsId(sId);
				MsgEmity me = this.findCountByKey(moduleManage, false);
				if (!me.isSuccess()) {
					return me.setData((Integer)me.getData() + 100);
				}
				
				int iCount = me.getData();
				if (iCount < 1) {
					return new MsgEmity(false, "未找到待设置的模块信息！", 7001);// 无法获取版本号,说明数据已经不存在
				}

				Log.error("设置未能得到预期影响值(预期1):", i);
				return new MsgEmity(false, "设置数据失败！", 7002);
			}
		} catch (Exception e) {
			Log.error("修改操作发生异常:", e.getMessage());
			return new MsgEmity(false, "设置失败！", 7003);
		}
		
		return new MsgEmity(true, "设置成功！", 7999);
	}
	
}
